package com.xgluo;

import com.xgluo.staticInerStaticClass.StaticInternalStaticClass;

import java.lang.reflect.Constructor;


/**
 * @author xgluo
 * @program SingleTon
 * @name DestorySingleMain
 * @description 破坏单例模式的场景
 * @date 2025年03月20日
 */
public class DestorySingleMain {

    // 反射破坏单例模式
    public static void main(String[] args) throws Exception {

        Class<?> aClass = Class.forName(StaticInternalStaticClass.class.getName());
        Constructor<?> staticInternalStaticClassConstrucor = aClass.getDeclaredConstructor();
        staticInternalStaticClassConstrucor.setAccessible(true);
        StaticInternalStaticClass singleton1 = (StaticInternalStaticClass)staticInternalStaticClassConstrucor.newInstance();
        StaticInternalStaticClass singleton2 = StaticInternalStaticClass.getInstance();

        System.out.println(singleton1 == singleton2 ? "单例模式" : "不是单例模式");
    }


}
